<!--
 * @Description: canvas
 * @Author: rendc
 * @Date: 2021-09-15 09:15:01
 * @LastEditors: rendc
 * @LastEditTime: 2021-09-15 09:25:47
-->
<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>canvas</title>
</head>

<body>
  <div id="app">
    <canvas id="canvas" width="300" height="300"></canvas>
  </div>
</body>
<script>
  var canvas = document.getElementById('canvas');
  // 检查浏览器是否支持canvas
  if (canvas.getContext) {
    // 支持canvas
    var ctx = canvas.getContext('2d');
    ctx.fillStyle = 'green';
    ctx.fillRect(10, 10, 100, 100);
  } else {
    alert("您的浏览器不支持canvas")
  }
</script>

</html>